home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLGR106.ARJ / LINE.C < prev    next >
Text File  |  1991-03-06  |  1KB  |  69 lines

  1. /* This is file LINE.C */
  2. /*
  3. ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. GrLine(x1, y1, x2, y2, c)
  16. {
  17.   int dx, dy, sx, sy;
  18.   int count;
  19.   int brc, brmax;
  20.  
  21.   sx = sy = 1;
  22.   dx = x2 - x1;
  23.   dy = y2 - y1;
  24.   if (dx < 0)
  25.   {
  26.     dx *= -1;
  27.     sx *= -1;
  28.   }
  29.   if (dy < 0)
  30.   {
  31.     dy *= -1;
  32.     sy *= -1;
  33.   }
  34.   if (dx > dy)
  35.   {
  36.     brmax = dx;
  37.     brc = dx / 2;
  38.     GrPlot(x1, y1, c);
  39.     for (count = dx; count; count--)
  40.     {
  41.       x1 += sx;
  42.       brc += dy;
  43.       if (brc > brmax)
  44.       {
  45.         brc -= dx;
  46.         y1 += sy;
  47.       }
  48.       GrPlot(x1, y1, c);
  49.     }
  50.   }
  51.   else
  52.   {
  53.     brmax = dy;
  54.     brc = dy / 2;
  55.     GrPlot(x1, y1, c);
  56.     for (count = dy; count; count--)
  57.     {
  58.       y1 += sy;
  59.       brc += dx;
  60.       if (brc > brmax)
  61.       {
  62.         brc -= dy;
  63.         x1 += sx;
  64.       }
  65.       GrPlot(x1, y1, c);
  66.     }
  67.   }
  68. }
  69.